<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no"/>
    <title>首页</title>
    <link rel="stylesheet" type="text/css" href="../c/aui.css"/>
    <style>
        .sx-money .aui-card-list-footer {
            padding: 0;
        }

        .sx-list .aui-card-list-footer {
            color: #fff;
            border-bottom: 1px solid #060606
        }

        .sx-money {
            background: #eba825;
            border-radius: 0.75rem;
            margin: 0.75rem;
            /*box-shadow:0px 0px 30px -5px #eba825;*/
            padding: 0.75rem;
            /*margin-top: 0;*/
            padding-bottom: 0rem;
            /*opacity: 0.8*/
        }

        .sx-t .l p {
            font-size: 0.75rem;
            color: #fff;
            letter-spacing: 1.5px;
            padding-bottom: 0.35rem;
        }

        .sx-t .l p span {
            padding-left: 0.5rem;
        }

        .sx-t .l b {
            font-size: 1.8rem;
            color: #fff;
            letter-spacing: 1.5px;
            font-weight: 400
        }

        .sx-t .r {
            background: #FE2C55;
            color: #fff;
            border-radius: 1rem;
            padding: 0.25rem 0.75rem;
            font-size: 0.85rem;
        }

        .sx-b {
            display: flex;
            padding: 0.75rem 0;
        }

        .sx-b .l {
            width: 50%;
        }

        .sx-b div {
            letter-spacing: 1.5px;
        }

        .sx-b div p {
            padding-bottom: 0.25rem;
            font-size: 0.75rem;
        }

        .sx-b div b {
            font-size: 0.95rem;
            font-weight: normal;
        }

        .sx-footer {
            background: #ca8809;
            margin: 0 -0.75rem;
            padding: 0.35rem 0.75rem;
            border-bottom-left-radius: 0.75rem;
            border-bottom-right-radius: 0.75rem;
            font-size: 0.75rem;
            letter-spacing: 1.5px
        }

        .sx-footer b {
            font-weight: normal;
        }

        .aui-card-list, .aui-card-list li, .aui-card-list ul, .aui-list .aui-list-item {
            background: none;
            border: 0;
            color: #fff;
        }

        .sx-list {
            border-top: 0.35rem solid #000;
        }

        .aui-list .aui-list-item-text {
            color: #fff;
            font-size: 0.7rem;
        }

        .title {
            font-size: 0.85rem;
        }

        .time {
            opacity: 0.5;
        }

        .sx-list .money {
            position: absolute;
            right: 0.75rem;
            top: 1rem;
            color: #eba825;
        }
    </style>
</head>

<body>
<div class="aui-content">
    <div class="sx-money">
        <div class="aui-card-list-footer sx-t">
            <div class="l">
                <p>可提现金额</p>
                <b>0</b>
            </div>
            <!-- <div class="r" tapmode onclick="_url({title:'提现',url:'member_tixian',_right_title:'提现记录',_right_url:'member_tixian_list'})">立即提现</div> -->
            <div class="r" tapmode onclick="tixian()">立即提现</div>
        </div>
        <div class="sx-b">
            <div class="l">
                <p>店铺保证金</p>
                <b>0</b>
            </div>
            <div class="r">
                <p>团队分销分润收益</p>
                <b>0</b>
            </div>
        </div>
        <div class="sx-footer">
            总收益： <b>0</b>
        </div>
    </div>
    <div class="sx-list">
        <div class="aui-card-list">
            <div class="aui-card-list-content">
                <div class="aui-card-list-footer">
                    <div>流水日志描述</div>
                    <div>流水金额</div>
                </div>
                <script id="sx-list" type="text/x-dot-template">
                    {{ for(var i=0,it=it.data; i < it.length; i++) { }}
                    <li class="aui-list-item aui-list-item-middle">
                        <div class="aui-media-list-item-inner">
                            <div class="aui-list-item-inner">
                                <div class="aui-list-item-text  title">
                                    {{= it[i].describess }}
                                </div>
                                <div class="aui-list-item-text time">
                                    {{= it[i].create_at_txt }}
                                </div>
                                <div class="money" {{? it[i].type== 2}}style="color:#9c9c9c" {{?}}>￥{{= it[i].money /
                                    100 }}
                                </div>
                            </div>
                        </div>
                    </li>
                    {{ } }}
                </script>
                <ul class="aui-list aui-media-list" id="sx-view">
                    <div id="loadingdi_huifu"><img src="../i/footer_progress.png"/></div>
                </ul>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="../j/api.js"></script>
<script type="text/javascript">
    apiready = function () {
        var bind_data = {}
        info();
        url = 'member/mwl';
        _list({url: url, loading: 1});
        _shangla(function (ret, err) {
            info();
            _list({url: url, loading: 1});
        }, 1)
        // 监听滚动
        api.addEventListener({
            name: 'scrolltobottom',
        }, function (ret, err) {
            if (heigutgao == 1) {
                pagenum += 1
                _list({url: url, page: pagenum});
            }
        });
        // 回到屏幕
        api.addEventListener({
            name: 'viewappear'
        }, function (ret, err) {
            info();
        });
    }

    function info() {
        _ajax('member/wallet', function (ret, err) {
            _so(ret);
            if (ret) {
                bind_data = ret.band;
                // $('.sx-t .l p span').text('(约'+ret.money+'元)');
                $('.sx-t .l b').text('￥' + ret.k1);
                $('.sx-b .l b').text('￥' + ret.k2);
                $('.sx-b .r b').text('￥' + ret.k3);
                $('.sx-footer b').text('￥' + ret.k4);
            } else {
                _alert(JSON.stringify(err));
            }
        })
    }

    function tixian() {
        // 绑定微信账户实名认证真实姓名
        if (!bind_data.weixin) {
            api.prompt({
                title: '首次提现',
                msg: '请绑定微信实名认证真实姓名',
                buttons: ['确定', '取消']
            }, function (ret, err) {
                var index = ret.buttonIndex;
                var text = ret.text;
                if (index == 1) {
                    if (!isChinese(text)) {
                        return _msg('请输入中文姓名');
                    } else {
                        bindRealName(text, pay)

                    }
                }
            });


        } else {
            // 再次确认绑定微信账户实名认证真实姓名
            api.prompt({
                title: '提示',
                msg: '检测到您之前绑定了微信实名认证真实姓名，是否使用该姓名？',
                text: bind_data.weixin.data.xingming,
                buttons: ['确定', '取消']
            }, function (ret, err) {
                var index = ret.buttonIndex;
                var text = ret.text;
                console.log(index, text)

                if (index == 1) {
                    if (!isChinese(text)) {
                        return _msg('请输入中文姓名');
                    } else {

                        // 更新真实姓名
                        if (text != bind_data.weixin.data.xingming) {
                            bindRealName(text, pay)
                        } else {
                            // 直接提交
                            api.prompt({
                                title: '输入提现金额',
                                msg: '根据微信提现要求,单次提现不超过3000元',
                                buttons: ['确定', '取消']
                            }, function (ret, err) {
                                var index = ret.buttonIndex;
                                var text = ret.text;
                                if (index == 1) {
                                    if (!isNum(text)) {
                                        return _msg('请输入1-3000的数字');
                                    } else {
                                        // 直接提交
                                        tixianSubmit(text, 2, bind_data.weixin.id, 1);


                                    }
                                }
                            });
                        }

                    }
                }
            });

        }
    }

    // 绑定微信认证实名
    function bindRealName(text, pay) {
        _loading();
        _ajax('member/tixian_band_add', function (ret, err) {
            _loadingCloes();
            if (ret) {
                api.alert({
                    title: '提示',
                    msg: '实名绑定成功',
                }, function (ret, err) {
                    info()
                });

            } else {
                _alert(JSON.stringify(err));
            }
        }, {xingming: text, pay: pay})
    }

    // 提现提交
    function tixianSubmit(money, pay, band_id, type) {
        _loading();
        _ajax('member/withdraw', function (ret, err) {
            _loadingCloes();
            if (ret) {
                if (ret.ret) {
                    _msg(ret.ret);
                    info()
                    _list({url: url, loading: 1});
                } else {
                    _alert(ret.err)
                }
            } else {
                _alert(JSON.stringify(err));
            }
        }, {money: money, pay: pay, band_id: band_id, type: type})
    }

    // 检测是否为中文
    function isChinese(temp) {
        var pattern = new RegExp("[\u4E00-\u9FA5]+");
        if (pattern.test(temp)) return true;
        return false;
    }

    // 检测是否为数字
    function isNum(temp) {
        var pattern = new RegExp("^[1-9]\\d*$");
        if (pattern.test(temp) && temp >= 1 && temp <= 1000) return true;
        return false;
    }
</script>

</html>
